/**
 *  Copyright (c)  2011-2020 Panguso, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Panguso, 
 *  Inc. ("Confidential Information"). You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into with Panguso.
 */

package cn.edu.thu.log.web.service.impl;

import cn.edu.thu.log.activity.abstraction.FromActivityTagXMLToTree;
import cn.edu.thu.log.tree.ManyTree;
import cn.edu.thu.log.tree.ManyTreeNode;
import cn.edu.thu.log.web.service.ActivityAbstractReadService;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdom.Element;
import org.jdom.JDOMException;

/**
 * 
 * @author wan
 */
public class ActivityAbstractReadServiceImpl implements
		ActivityAbstractReadService {
	private static ActivityAbstractReadService singleton = null;
	private ManyTree manyTree;
	private String filename;
/**
 * 
 * @return
 */
	public static synchronized ActivityAbstractReadService instance() {
		if (singleton == null) {
			singleton = new ActivityAbstractReadServiceImpl();
		}
		return singleton;
	}

	@Override
	public void readActivityConfig() {
		// 获取日志清洗xml中的根节点
		try {
			// 创建ManyTree树
			FromActivityTagXMLToTree xmlTree = new FromActivityTagXMLToTree();
			// 读取到xml中表示树的根节点
			Element treexmlroot = xmlTree.readActivityXML(filename);
			// 生成多叉树
			ManyTreeNode treeroot = xmlTree.createTree(treexmlroot);
			manyTree = new ManyTree(treeroot);		

		} catch (JDOMException ex) {
			Logger.getLogger(ActivityAbstractReadServiceImpl.class.getName())
					.log(Level.SEVERE, null, ex);
		}
	}

	@Override
	public ManyTree getManyTree() {
		return manyTree;
	}

	/**
	 * @param manyTree the manytree to set
	 */
	@Override
	public void setManyTree(ManyTree manyTree) {
		this.manyTree = manyTree;
	}

	@Override
	public void setActivityAbstractFileName(String filename1) {
		this.filename = filename1;
	}
}
